/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jrill.notification;

import java.net.URL;
import java.util.Arrays;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.jrill.Participant;

/**
 *
 * @author K.Waga <kzwaga@gmail.com>
 */
public class StdoutNotifier implements Notifier {

    private int notificationsSent = 0;

    /**
     * print notification to stdout and count notifications
     * @param sendTo
     * @param copyTo
     * @param blindCopyTo
     * @param subject
     * @param note
     * @param link
     */
    public void send(Participant[] sendTo, Participant[] copyTo, Participant[] blindCopyTo, String subject, String note, URL link) {
        notificationsSent++;
        System.out.println(new ToStringBuilder(this).append("sendTo", sendTo).append("cc", copyTo).append("bcc", blindCopyTo).append("subject", subject).append("note", note).append("link", link).toString());
    }

    /**
     * @return the notificationsSent
     */
    public int getNotificationsSent() {
        return notificationsSent;
    }

    /**
     * @param notificationsSent the notificationsSent to set
     */
    public void setNotificationsSent(int notificationsSent) {
        this.notificationsSent = notificationsSent;
    }

    public void send(Participant[] sendTo, Participant[] copyTo, Participant[] blindCopyTo, MessageTemplate messageTemplate) {
        
        notificationsSent += (sendTo != null ? sendTo.length : 0) + (copyTo !=null ? copyTo.length : 0) + (blindCopyTo != null ? blindCopyTo.length : 0);
        System.out.println("* * * TOP OF NOTIFICATION * * *");
        System.out.println("To :" + (sendTo != null ?
                Arrays.asList(sendTo)
                : "<empty>"));
        System.out.println("Cc :" + (copyTo != null ?
                Arrays.asList(copyTo)
                : "<empty>"));
        System.out.println("Bcc:" + (blindCopyTo != null ?
                Arrays.asList(blindCopyTo)
                : "<empty>"));
        System.out.println("Subject:" + messageTemplate.evaluateSubject());
        System.out.println("body:" + messageTemplate.evaluateBody());
        System.out.println("link:" + messageTemplate.evaluateLinkUrl());
        System.out.println("* * * BOTTOM OF NOTIFICATION * * *");
    }

}
